home *** CD-ROM | disk | FTP | other *** search
/ Creating Your Own America Online Web Pages / Creating Your Own America Online Web Pages.iso / TOOLS / TEX2RTF / SOURCES.ZIP / SRC / WXWIN / WX_LIST.H < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  4.4 KB  |  151 lines

  1. /*
  2.  * File:     wx_list.h
  3.  * Purpose:  wxList implementation much used in wxWindows
  4.  *
  5.  *                       wxWindows 1.50
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                       Date: 7-9-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29. #ifndef wxb_listh
  30. #define wxb_listh
  31.  
  32. #include "wx_obj.h"
  33.  
  34. #ifdef IN_CPROTO
  35. typedef       void    *wxList ;
  36. typedef       void    *wxNode;
  37. typedef       void    *wxStringList;
  38. #else
  39.  
  40. class wxList;
  41.  
  42. #define wxKEY_NONE    0
  43. #define wxKEY_INTEGER 1
  44. #define wxKEY_STRING  2
  45. class wxNode: public wxObject
  46. {
  47.   wxObject *data;
  48.   wxNode *next;
  49.   wxNode *previous;
  50.  
  51.  public:
  52.   wxList *list;
  53.  
  54.   // Optional key stuff
  55.   union
  56.   {
  57.     long integer;
  58.     char *string;
  59.   } key;
  60.  
  61.   wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one, wxObject *object);
  62.   wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
  63.          wxObject *object, long the_key);
  64.   wxNode(wxList *the_list, wxNode *last_one, wxNode *next_one,
  65.          wxObject *object, char *the_key);
  66.   ~wxNode(void);
  67.  
  68.   inline wxNode *Next(void) { return next; }
  69.   inline wxNode *Previous(void) { return previous; }
  70.   inline wxObject *Data(void) { return data; }
  71.   inline void SetData(wxObject *the_data) { data = the_data; }
  72. };
  73.  
  74. class wxList: public wxObject
  75. {
  76.  public:
  77.   int n;
  78.   int destroy_data;
  79.   wxNode *first_node;
  80.   wxNode *last_node;
  81.   unsigned int key_type;
  82.  
  83.   wxList(void);
  84.   wxList(unsigned int the_key_type);
  85.   wxList(int N, wxObject *Objects[]);
  86.   wxList(wxObject *object, ...);
  87.   ~wxList(void);
  88.  
  89.   inline int Number(void) { return n; }
  90.  
  91.   // Append to end of list
  92.   inline wxNode *Append(wxObject *object)
  93.   {
  94.     wxNode *node = new wxNode(this, last_node, NULL, object);
  95.     if (!first_node)
  96.       first_node = node;
  97.     last_node = node;
  98.     n ++;
  99.     return node;
  100.   }
  101.  
  102.   // Insert at front of list
  103.   wxNode *Insert(wxObject *object);
  104.  
  105.   // Insert before given node
  106.   wxNode *Insert(wxNode *position, wxObject *object);
  107.  
  108.   // Keyed append
  109.   wxNode *Append(long key, wxObject *object);
  110.   wxNode *Append(char *key, wxObject *object);
  111.  
  112.   Bool DeleteNode(wxNode *node);
  113.   Bool DeleteObject(wxObject *object);  // Finds object pointer and
  114.                                         // deletes node (and object if
  115.                                         // DeleteContents is on)
  116.   void Clear(void);                     // Delete all nodes
  117.  
  118.   inline wxNode *First(void) { return first_node; }
  119.   inline wxNode *Last(void) { return last_node; }
  120.   wxNode *Nth(int i);                  // nth node counting from 0
  121.  
  122.   // Keyed search
  123.   wxNode *Find(long key);
  124.   wxNode *Find(char *key);
  125.  
  126.   wxNode *Member(wxObject *object);
  127.  
  128.   inline void DeleteContents(int destroy) { destroy_data = destroy; }
  129.                                              // Instruct it to destroy user data
  130.                                              // when deleting nodes
  131. };
  132.  
  133. // String list class. N.B. this always copies strings
  134. // with Add and deletes them itself.
  135. class wxStringList: public wxList
  136. {
  137.  public:
  138.   wxStringList(void);
  139.   wxStringList(char *first ...);
  140.   ~wxStringList(void);
  141.  
  142.   virtual wxNode *Add(char *s);
  143.   virtual void Delete(char *s);
  144.   virtual char **ListToArray(Bool new_copies = FALSE);
  145.   virtual void Sort(void);
  146.   virtual Bool Member(char *s);
  147. };
  148.  
  149. #endif // IN_CPROTO
  150. #endif // wxb_listh
  151.